package com.basketball.gym.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.basketball.gym.pojo.Feedback;
import com.basketball.gym.pojo.ResponseData;
import com.basketball.gym.pojo.User;
import com.basketball.gym.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 赵肖云
 * @since 2021-04-10
 */
@Api(tags = "反馈管理")
@RestController
@RequestMapping("/gym/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    @ApiOperation("提交反馈")
    @PreAuthorize("hasRole('user')")
    @PostMapping
    public ResponseData<Feedback> postFeedback(@RequestBody Feedback feedback,@ApiIgnore @ModelAttribute("activeUser")User user){
        return feedbackService.postFeedback(feedback,user);
    }

    @ApiOperation("查询我的反馈")
    @PreAuthorize("hasRole('user')")
    @GetMapping
    public ResponseData<List<Feedback>> getMyFeedback(@ApiIgnore @ModelAttribute("activeUser")User user){
        return feedbackService.getMyFeedback(user);
    }

    @ApiOperation("查询所有反馈")
    @GetMapping("/all")
    public ResponseData<IPage<Feedback>> adminGetFeedback(Feedback feedback){
        return feedbackService.adminGetFeedback(feedback);
    }
}

